<script>
$(document).ready(function(){
	$("#selKind").change(getCommentList);
	$("#selLevel").change(getCommentList);

	$("#commentManagerAppendBtn").click(function(){
        $("#comment-manager-data tbody").append('<tr><td><input type="text" size=20 name="new_ManagerName[]" /></td>'+
                '<td><input type="button" class="cancelBtn" value="<?php echo $this->translate("cancel")?>" /></td></tr>');
        checkCommentManagerIsEmpty();
      });

	 $(".cancelBtn").live('click',function(){
         $(this).parents('tr').remove();
         checkCommentManagerIsEmpty();
      });

	   $("#commentManagerSaveBtn").click(function(){
		   $("#kind_sn").val($("#selKind").val());
		   $("#kind_level").val($("#selLevel").val());
		    $("#commentManager").submit();

		    checkCommentManagerIsEmpty();
	   });

     // 列出評語
     getCommentList();

});

function checkCommentManagerIsEmpty() {
    if ($("#commentManager input:[type='text']").length == 0)
        $("#commentManagerSaveBtn").attr('disabled','disabled');
    else
        $("#commentManagerSaveBtn").attr('disabled','');
}


// get comment List
function getCommentList() {
$.get('<?php echo $this->route("comment-list-table")?>',
        {
            kindSn: $("#selKind").val(),
            levelSn: $("#selLevel").val()
        },
        function(data){
            $("#comment-list-table").html(data);
            //檢查編修狀態
            checkCommentManagerIsEmpty();
            }
        );

}


</script>
<div id="comment-manager-data">
<div style="float: left">
<div style="width: 300px; text-align: right">
<form method="post" id="commentForm" action="comment-save">
<select name="kind" id="selKind">
<?php foreach($this->kindData as $val):?>
	<option value="<?php echo $val['sn']?>"><?php echo $val['name']?></option>
	<?php endforeach;?>
</select> <select name="level" id="selLevel">
<?php foreach($this->levelData as $val):?>
	<option value="<?php echo $val['sn']?>"><?php echo $val['name']?></option>
	<?php endforeach;?>
</select>
 <input type="button" id="commentManagerSaveBtn"
	value="<?php echo $this->translate('save')?>" />
<input type="button"
	id="commentManagerAppendBtn" value="<?php echo $this->translate('append')?>" />
</form>
</div>
<div id="comment-list-table"></div>
</div>
<div style="clear: both"></div>
</div>
